<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" :inline="true" label-position="right" label-width="100px">
      <el-form-item label="job主键" prop="jobId">
        <el-input
          v-model="queryParams.jobId"
          placeholder="请输入job主键"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="job状态" prop="isSuccess">
        <el-select v-model="queryParams.isSuccess" clearable placeholder="请选择job状态" width="100%" @keyup.enter.native="handleQuery">
          <el-option
            v-for="item in jobStatusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="任务开始时间" prop="startTime">
        <el-date-picker
          v-model="queryParams.startTime"
          clearable
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择任务开始时间"
        />
      </el-form-item>
      <el-form-item label="标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="nlp状态" prop="isNlpSuccess">
        <el-select v-model="queryParams.isNlpSuccess" clearable placeholder="请选择nlp状态" @keyup.enter.native="handleQuery">
          <el-option
            v-for="item in nlpOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="nlp消耗时间" prop="nlpTime">
        <el-input
          v-model="queryParams.nlpTime"
          placeholder="请输入nlp消耗时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="tts状态" prop="isTtsSuccess">
        <el-select v-model="queryParams.isTtsSuccess" clearable placeholder="请选择tts状态" @keyup.enter.native="handleQuery">
          <el-option
            v-for="item in ttsOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="tts消耗时间" prop="ttsTime">
        <el-input
          v-model="queryParams.ttsTime"
          placeholder="请输入tts消耗时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="tts任务总数" prop="ttsTaskNum">
        <el-input
          v-model="queryParams.ttsTaskNum"
          placeholder="请输入tts任务总数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合成服务状态" prop="isComposeSuccess">
        <el-select v-model="queryParams.isComposeSuccess" clearable placeholder="请选择合成服务状态" @keyup.enter.native="handleQuery">
          <el-option
            v-for="item in composeOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="合成消耗时间" prop="composeTime">
        <el-input
          v-model="queryParams.composeTime"
          placeholder="请输入合成消耗时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="job创建者" prop="jobCreateBy">
        <el-input
          v-model="queryParams.jobCreateBy"
          placeholder="请输入job创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段1" prop="backup1">
        <el-input
          v-model="queryParams.backup1"
          placeholder="请输入备用字段1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="消耗总时间" prop="backup2">
        <el-input
          v-model="queryParams.backup2"
          placeholder="请输入消耗总时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格部分 -->
    <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" /> -->
      <el-table-column label="job主键" width="155" prop="jobId" />
      <el-table-column label="标题" prop="title" width="230" />
      <el-table-column label="下载" prop="backup1" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.backup1 === '0'"> --</span>
          <el-button v-else size="mini" plain @click="downloadVedio(scope.row.backup1)">下载</el-button>
        </template>
      </el-table-column>
      <el-table-column label="nlp消耗时间(s)" prop="nlpTime" width="110" />
      <el-table-column label="tts消耗时间(s)" prop="ttsTime" width="110" />
      <el-table-column label="合成消耗时间(s)" prop="composeTime" width="115" />
      <el-table-column label="消耗总时间(s)" prop="id" width="110" />
      <el-table-column label="tts任务总数" prop="ttsTaskNum" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="job状态" prop="isSuccess" width="130">
        <template slot-scope="scope">
          <span v-if="scope.row.isSuccess === '1'">完成</span>
          <span v-if="scope.row.isSuccess === '0'">正在运行</span>
          <span v-if="scope.row.isSuccess === '-1'">NLP任务失败</span>
          <span v-if="scope.row.isSuccess === '-2'">TTS任务失败</span>
          <span v-if="scope.row.isSuccess === '-3'">合成任务失败</span>
          <span v-if="scope.row.isSuccess === '-4'">检查失败</span>
          <span v-if="scope.row.isSuccess === '-5'">Job没有提交</span>
          <span v-if="scope.row.isSuccess === '-6'">排队NLP</span>
          <span v-if="scope.row.isSuccess === '-7'">正在NLP</span>
          <span v-if="scope.row.isSuccess === '-8'">排队TTS</span>
          <span v-if="scope.row.isSuccess === '-9'">正在TTS</span>
          <span v-if="scope.row.isSuccess === '-10'">排队合成</span>
          <span v-if="scope.row.isSuccess === '-11'">正在合成</span>
        </template>
      </el-table-column>
      <el-table-column label="tts状态" prop="isTtsSuccess">
        <template slot-scope="scope">
          <span v-if="scope.row.isTtsSuccess === '1'">成功</span>
          <span v-if="scope.row.isTtsSuccess === '-1'">失败</span>
        </template>
      </el-table-column>
      <el-table-column label="合成服务状态" prop="isComposeSuccess" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.isComposeSuccess === '1'">成功</span>
          <span v-if="scope.row.isComposeSuccess === '-1'">失败</span>
        </template>
      </el-table-column>
      <el-table-column label="job创建者" prop="jobCreateBy" />
      <el-table-column label="创建时间" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </el-form></div>
</template>

<script>
import { getHistoryList } from '@/api/rateLimiter/RateLimitInfo'
// import { treeselect as menuTreeselect, roleMenuTreeselect } from '@/api/system/menu'
// import { treeselect as deptTreeselect, roleDeptTreeselect } from '@/api/system/dept'
import { download } from './download.js'
export default {
  name: 'Role',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],
      // 状态数据字典
      statusOptions: [],
      // 数据范围选项
      jobStatusOptions: [
        {
          value: '1',
          label: '完成'
        },
        {
          value: '0',
          label: '正在运行'
        },
        {
          value: '-1',
          label: 'NLP任务失败'
        },
        {
          value: '-2',
          label: 'TTS任务失败'
        },
        {
          value: '-3',
          label: '合成任务失败'
        },
        {
          value: '-4',
          label: '检查失败'
        },
        {
          value: '-5',
          label: 'Job没有提交'
        },
        {
          value: '-6',
          label: '排队NLP'
        },
        {
          value: '-7',
          label: '正在NLP'
        },
        {
          value: '-8',
          label: '排队TTS'
        },
        {
          value: '-9',
          label: '正在TTS'
        },
        {
          value: '-10',
          label: '排队合成'
        },
        {
          value: '-11',
          label: '正在合成'
        }
      ],
      nlpOptions: [
        {
          value: '1',
          label: '成功'
        },
        {
          value: '-1',
          label: '失败'
        }
      ],
      ttsOptions: [
        {
          value: '1',
          label: '成功'
        },
        {
          value: '-1',
          label: '失败'
        }
      ],
      composeOptions: [
        {
          value: '1',
          label: '成功'
        },
        {
          value: '-1',
          label: '失败'
        }
      ],
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        jobId: '',
        isSuccess: '',
        startTime: '',
        title: '',
        isNlpSuccess: '',
        nlpTime: '',
        isTtsSuccess: '',
        ttsTime: '',
        ttsTaskNum: '',
        isComposeSuccess: '',
        composeTime: '',
        jobCreateBy: '',
        backup1: '',
        backup2: ''
      },
      // 表单参数
      form: {},
      defaultProps: {
        children: 'children',
        label: 'label'
      },

      // 表单校验
      rules: {
        roleName: [
          { required: true, message: '角色名称不能为空', trigger: 'blur' }
        ],
        roleKey: [
          { required: true, message: '权限字符不能为空', trigger: 'blur' }
        ],
        roleSort: [
          { required: true, message: '角色顺序不能为空', trigger: 'blur' }
        ]
      }
    }
  },

  created() {
    this.getList()
    this.getDicts('sys_normal_disable').then(response => {
      this.statusOptions = response.data
    })
  },

  methods: {
    /** 查询角色列表 */
    getList() {
      this.loading = true
      getHistoryList(this.queryParams).then(response => {
        console.log(response)
        this.roleList = response.data.list
        this.total = response.data.total
        this.loading = false
      })
    },

    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },

    // 表单重置
    reset() {
      this.form = {
        id: null,
        jobId: null,
        isSuccess: null,
        startTime: null,
        title: null,
        isNlpSuccess: null,
        nlpTime: null,
        isTtsSuccess: null,
        ttsTime: null,
        ttsTaskNum: null,
        isComposeSuccess: null,
        composeTime: null,
        jobCreateBy: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        backup1: null,
        backup2: null
      }
      this.resetForm('form')
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.roleId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    downloadVedio(url) {
      window.open(url)
    }
  }
}
</script>
<style lang="scss" scoped>
::v-deep .el-input {
  width: 220px;
}

::v-deep .el-select {
  width: 220px;
}

::v-deep .el-input__inner {
  width: 220px;
}
</style>
